﻿using Dapper_Core.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;

namespace Dapper_Core.Common
{
    public static class ResultBaseExt
    {
        /// <summary>
        /// 错误返回
        /// </summary>
        /// <param name="result"></param>     
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultBase ErrorResult(this ResultBase result, string message)
        {
            result.IsSuccess = false;
            result.Message = message;
            return result;
        }

        /// <summary>
        /// 错误返回 --枚举
        /// </summary>
        /// <param name="result"></param>     
        /// <param name="eresult"></param>
        /// <param name="errMessage"></param>
        /// <returns></returns>
        public static ResultBase ErrorResult(this ResultBase result, EResult eresult)
        {
            result.IsSuccess = false;
            result.Message = eresult.GetDescription();
            return result;
        }

        /// <summary>
        /// 错误返回
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="result"></param>     
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultBase<TModel> ErrorResult<TModel>(this ResultBase<TModel> result, string message)
        {
            result.IsSuccess = false;
            result.Message = message;
            return result;
        }

        /// <summary>
        /// 错误返回 --枚举
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="result"></param>
        /// <param name="eresult"></param>   
        /// <returns></returns>
        public static ResultBase<TModel> ErrorResult<TModel>(this ResultBase<TModel> result, EResult eresult)
        {
            result.IsSuccess = false;
            result.Message = eresult.GetDescription();
            return result;
        }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="result"></param>
        /// <param name="Message"></param>
        /// <returns></returns>
        public static ResultBase SuccessResult(this ResultBase result, string Message)
        {
            result.IsSuccess = true;
            result.Message = Message;
            return result;
        }

        /// <summary>
        /// 成功返回 --枚举
        /// </summary>
        /// <param name="result"></param>
        /// <param name="eresult"></param>      
        /// <returns></returns>
        public static ResultBase SuccessResult(this ResultBase result, EResult eresult = EResult.N0000)
        {
            result.IsSuccess = true;
            result.Message = eresult.GetDescription();
            return result;
        }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="result"></param>
        /// <param name="model"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResultBase<TModel> SuccessResult<TModel>(this ResultBase<TModel> result, TModel data, string message)
        {
            result.IsSuccess = true;
            result.Message = message;
            result.Data = data;
            return result;
        }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="result"></param>
        /// <param name="model"></param>
        /// <param name="eresult"></param>
        /// <returns></returns>
        public static ResultBase<TModel> SuccessResult<TModel>(this ResultBase<TModel> result, TModel data, EResult eresult = EResult.N0000)
        {
            result.IsSuccess = true;
            result.Message = eresult.GetDescription();
            result.Data = data;
            return result;
        }
    }
}
